<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">班次名称：</label>
                                    <div class="layui-input-inline">
                                        <input name="banName" class="layui-input" type="text" placeholder="请输入班次名称"
                                               autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="deviceWorkshopBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                        </div>
                        <div class="lay-btn-rt">
                            <button id="syncDingBanData" class="layui-btn icon-btn color-reseda">同步班次数据</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="workStationTable" lay-filter="workStationTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="workStationTableBar">
            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="seeAttendanceDetail">详情</a>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;


        // 渲染表格
        var insTb = table.render({
            elem: '#workStationTable',
            url: config.base + 'enterprise/res/admin/dingTalkAttendanceBan/list',
            page: true,
            toolbar: true,
            defaultToolbar: ["filter"],
            cellMinWidth: 100,
            cols: [[
                  {type: 'numbers', title: '序号'}
                , {field: 'banName', sort: false, title: '班次名称'}
                , {field: 'workBeginTime', sort: false, title: '上班时间'}
                , {field: 'workEndTime', sort: false, title: '下班时间'}
                , {field: 'restBeginTime', sort: false, title: '休息开始时间'}
                , {field: 'restEndTime', sort: false, title: '休息结束时间'}
                , {field: 'creator', sort: false, title: '添加人'}
                , {field: 'createTime', sort: false, title: '添加时间'}
                , {align: 'center', toolbar: '#workStationTableBar', title: '操作', width: 200}
             ]]
        });


        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        //监听排序
        table.on('sort(workStationTable)', function (obj) {
            table.reload('workStationTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 添加按钮点击事件
        $('#deviceWorkshopBtnAdd').click(function () {

        });

        //同步班次数据
        $('#syncDingBanData').click(function () {
            syncDingBanDataFunction();
        });

        function syncDingBanDataFunction() {
            layer.confirm('确定要同步班次数据吗？', {
                offset: '265px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/res/admin/dingTalkAttendance/syncDingAttendanceBanCiSystem', {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});

                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                    table.reload('workStationTable');
                    layer.closeAll('page');
                }, 'GET');
            });
        }


        // 工具条点击事件
        table.on('tool(workStationTable)', function (obj) {
            let data = obj.data;
            if (obj.event === 'seeAttendanceDetail') {  //详情

            }
        });

    });
</script>